import request from '@/utils/request';

interface OpenIdResponse {
    code: number;
    msg: string;
    data: {
        openid: string;
        // 可能还会返回其他字段
    };
}

interface LoginResponse {
    code: number;
    msg: string;
    data: {
        token: string;
    };
}

interface UserInfo {
    code: number;
    msg: string;
    data: {
        id: string;
        openId: string;
        nickname: string;
        avatar?: string;
        createTime?: string;
        updateTime?: string;
    };
}

// 微信登录
export const wxLogin = (code: string): Promise<LoginResponse> => {
    return request.post('/api/user/wx-login', { code });
};

// 获取用户信息
export const getUserInfo = (): Promise<UserInfo> => {
    return request.get('/api/user/info');
};

// 获取OpenID
export const getOpenId = (code: string): Promise<OpenIdResponse> => {
    return request.get('/system/wechatUser/getInfoByCode', { params: { code } });
};

// 完善用户信息
export const updateUserInfo = (data: any): Promise<any> => {
    return request.put('/system/wechatUser', data);
};

// 处理登录，获取并存储openId
